<style lang="scss" scoped>
	.content {
		width: 100%;
		background-color: white;
		
		padding:30rpx 25rpx;
	}

	.list {
		
		border-bottom: 1px solid #ccc;
		align-items: flex-start;
		padding:25rpx 0;
		.red {
			transform: translateY(6rpx);
		}

		.textarea {
			width: 550rpx;
			height: 120rpx;
			font-size: 28rpx;
		}

		.mic {
			height: 120rpx;
			width: 80rpx;
			border-left: 1px solid #ccc;
			padding-left: 20rpx;
		}

		.ipt,.picker {
			width: 550rpx;
			text-align: right;
		}

		.uploadfile {
			width: 550rpx;

			.btns {
				width: 100%;
				justify-content: flex-end;
				.btn {
					padding:0 30rpx;
					height: 64rpx;
					opacity: 1;
					background: #fffefe;
					border: 2rpx solid #409eff;
					border-radius: 34rpx;
				}
			}
		}

		.record {
			width: 550rpx;
		}
	}
	.line2{
		width:100%;
		border-bottom: 1px solid #ccc;
		line-height:80rpx ;
		.line{
			width:100%;
			
			.t2{
				width:60%;
			}
		}
	}
	.footer {
		height: 160rpx;
		width: 750rpx;
		padding: 30rpx;
	
		background-color: white;
	
		.btn {
			width: 320rpx;
			height: 88rpx;
			border-radius: 44rpx;
		}
	}
</style>

<template>
	<view class="content">
		<view class="f34 bold" style="padding:0 30rpx;border-bottom: 1px solid #ccc;padding-bottom: 20rpx;">任务处理</view>
		<view class="list between-flex f28">
			<view class="align-flex p-left10 gray">
				<span class="red">*</span>处理人
			</view>
			<view class="picker blue align-flex choosearea" @click="$navTo(PagesCourseRouterConfig.ChoosePerson+'?type=2')">
				{{people?people.name:'请选择'}}
				<u-icon name='arrow-right'></u-icon>
			</view>
		</view>
		<view class="list between-flex f28">
			<view class="align-flex p-left10 gray">
				<span class="red">*</span>完成进度（单位：%）
			</view>
			<input style="text-align: right;" class="" type="number" v-model="progress" placeholder="请输入0~100整数" />
		</view>
		
		<view class="list between-flex f28">
			<view class="align-flex p-left10 gray">
				完成时间
			</view>
			<view class="picker blue " @click="showEndtime=true">
				{{endTime}} <u-icon name="arrow-right"></u-icon>
			</view>
		</view>
		
		<view class="list between-flex f28">
			<view class="align-flex p-left10 gray">
				<span class="red">*</span>处理描述
			</view>
			<textarea class="textarea"  v-model="remark" placeholder="请填写" />
		</view>
		
		<view class="list between-flex f28">
			<view class="align-flex">
				附件
			</view>
			<view class="uploadfile">
				<view class="btns align-flex m-bottom20">
					<view class="btn center-flex blue "  @click="chooseImg"  style="margin-right: 30rpx;">拍照</view>
					<view class="btn center-flex  blue" @click="uploadfile">上传附件</view>
				</view>
				<view class="p-top10 between-flex" v-for="item,index in enclosure" :key="index">
					<view class="align-flex blue" @click="$open(item.url)">
						<u-icon name="file-text" color="#409EFF" size="38"></u-icon>
						{{item.fileName.substring(item.fileName.length-10)}}
					</view>
					<u-icon @click="delfile(index)" name="close" color="#666666" size="30"></u-icon>
				</view>
			</view>
		</view>
		<view class="footer between-flex">
			<view style="border: 2rpx solid #409eff;" class="btn  blue center-flex f32 bold"  @click="submit(1)">
				完成
			</view>
			<view style="border: 2rpx solid #409eff;" class="btn  blue center-flex f32 bold" @click="submit(2)">
				处理 
			</view>
		</view>
		<u-picker v-model="showEndtime" mode="time" :params="params" @confirm="confirm($event,2)"></u-picker>
	</view>
</template>

<script>
	import PagesCourseRouterConfig from '@/pagesCourse/routerConfig.js'
	export default {
		props: {
			job: {
				default: {}
			}
		},
		data() {
			return {
				PagesCourseRouterConfig,
				head: this.$head,
				people:null,
				endTime:'',
				showEndtime:false,
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: false
				},
				enclosure:[],
				progress:'',
				remark:''
			}
		},
		
		created() {
			uni.$on('choosePerson',(data)=>{
				this.people=data
			})
			if(this.job.totalProgress){
				this.progress=this.job.totalProgress
			}
			this.getdate()
			this.people=this.$getUser()
		},
		beforeDestroy() {
			uni.$off('choosePerson')
		},
		methods: {
		
			submit(type) {
				var _this=this
				if (!this.people) {
					this.$msg('请选择处理人')
					return
				}
				if (!this.progress&&type==2) {
					this.$msg('请输入进度')
					return
				}
				if(this.progress!=parseInt(this.progress)||this.progress>100){
					this.$msg('请输入小于等于100的整数')
					return
				}
				if (!this.remark) {
					this.$msg('请输入处理描述')
					return
				}
				var obj={
					linkedKey:this.job.id,
					users:this.people.value,	
					updateTime:this.endTime,
					remark:this.remark
				}
				if(type==2){
					obj.progress=this.progress
				}else{
					obj.progress=100
				}
				if (this.enclosure.length > 0) {
					var enclosure = []
					this.enclosure.forEach(item => {
						enclosure.push({
							name: item.oldName,
							url: item.url
						})
					})
					obj['enclosure'] = JSON.stringify(enclosure)
				}
				
				console.log(obj)
				this.$showloading()
				this.$pop.ajaxPost("/busItemWork/make", obj).then(res => {
					uni.hideLoading()
					if(res.code==0){
						_this.$msg(res.msg)
						_this.$emit('submit')
					}else{
					this.$msg(res.msg)	
					}
				})
			},
			confirm(e,index){
				console.log(e)
				if(index==1){
					this.startTime=e.year+'-'+e.month+'-'+e.day+' '+e.hour+':'+e.minute
				}else{
					this.endTime=e.year+'-'+e.month+'-'+e.day+' '+e.hour+':'+e.minute
				}
			},
			getdate() {
				var date = new Date();
			
				this.date = parseInt(date.getTime() / 1000)
				var seperator1 = "-";
				var seperator2 = ":";
				var month = date.getMonth() + 1;
				var strDate = date.getDate();
				var hour = date.getHours()
				var min = date.getMinutes()
				month < 10 ? month = '0' + month : ''
				strDate < 10 ? strDate = '0' + strDate : ''
				hour < 10 ? hour = '0' + hour : ''
				min < 10 ? min = '0' + min : ''
				var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate+' '+hour+seperator2+min
			
				this.endTime = currentdate;
			},
			delfile(index) {
				this.enclosure.splice(index, 1)
			},
			//选择图片
			async chooseImg() {
			
				var file = await this.$chooseImg()
			
				this.enclosure.push(file)
			
			},
			async uploadfile() {
			
				var file = await this.$uploadfile()
				this.enclosure.push(file)
			
			},

		}
	}
</script>
